package com.googlecode.continuity.plugin.codecomment.client;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import com.googlecode.continuity.core.client.Message;

/**
 * CodeComment
 *
 * @author Peter Schmitt <aragos@aragos.de>
 */
public class CodeComment extends Message implements HasSeverity {
// ------------------------------ FIELDS ------------------------------

  private CodePointer location;
  private SeverityConstant severity;
  private Set relatedComments;

// --------------------------- CONSTRUCTORS ---------------------------

  // todo: add visibility, rating, parents

// --------------------- GETTER / SETTER METHODS ---------------------

  public CodePointer getLocation() {
    return location;
  }

  public void setLocation(CodePointer location) {
    this.location = location;
  }

  public SeverityConstant getSeverity() {
    return severity;
  }

  public void setSeverity(SeverityConstant severity) {
    this.severity = severity;
  }

  public Set getRelatedComments() {
    if (relatedComments == null) {
      relatedComments = new HashSet();
    }
    return relatedComments;
  }

  protected void addRelatedComment(CodeComment comment) {
    if (relatedComments == null) {
      relatedComments = new HashSet();
    }
    relatedComments.add(comment);
  }

  protected void removeRelatedComment(CodeComment related) {
    relatedComments.remove(related);
  }

  private void setRelatedComments(Set relatedSet) {
    // make sure it's really a hashset
    Iterator it = relatedSet.iterator();
    relatedComments = new HashSet(relatedSet.size());
    while (it.hasNext()) {
      relatedComments.add(it.next());
    }
  }
}
